import 'package:data/repository/projects/projects_repository.dart';
import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import '../util/test_json_loader.dart';

class MockDio extends Mock implements Dio {}

void main() {
  group('test repository', () {
    late MockDio mockDio;
    late Map<String, dynamic> testData;
    late ProjectsRepository repo;

    setUp(() {
      testData = TestJsonDataLoader.loadSingleJsonData('mock_projects.json');
      mockDio = MockDio();
      repo = ProjectsRepositoryImpl(dio: mockDio);
    });

    tearDown(() {
      reset(mockDio);
    });

    test('should return response', () async {
      final mockResponse = Response(
        statusCode: 200,
        data: testData,
        requestOptions: RequestOptions(),
      );

      when(() => mockDio.get(any())).thenAnswer((_) async => mockResponse);
      final result = await repo.fetchProjects(pageIndex: 1, categoryId: 1);
      expect(result.total, 293);
      expect(result.projects.isNotEmpty, true);
      expect(result.projects.length, 1);
      expect(
        result.projects.first.link,
        "https://www.wanandroid.com/blog/show/3775",
      );
      expect(result.projects.first.audit, 1);
    });
  });
}
